package com.google.rui.imagezoom.test;

import com.google.rui.utils.AndroidUtils;

import com.google.rui.demos.R;
import com.google.rui.imagezoom.BasicZoomControl;
import com.google.rui.imagezoom.ImageActivity;
import com.google.rui.imagezoom.ImageDisplayer;
import com.google.rui.imagezoom.ImageReceivedCallback;
import com.google.rui.imagezoom.ImageZoomView;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;

public class ImageZoomViewTest02 extends ImageActivity {

	ImageZoomView mImageZoomView;
	BasicZoomControl zoomCtrl;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.image_zoom_test);
		mImageZoomView = (ImageZoomView) findViewById(R.id.photo_zoom_view);

		zoomCtrl = new BasicZoomControl();
		mImageZoomView.mZoomControl = zoomCtrl;
		mImageZoomView.setZoomState(zoomCtrl.getZoomState());

		zoomCtrl.setAspectQuotient(mImageZoomView.getAspectQuotient());

		String imgPath=AndroidUtils.getSDCardPath()+"images/20120504090016.jpg";
		
		new Thread(new LoadImageData(this, mImageZoomView,imgPath)).start();
	}

	class LoadImageData implements Runnable {

		ImageReceivedCallback mCallback;
		ImageZoomView mView;
		String mPhotoPathName;
		Bitmap mBitmap;

		LoadImageData(ImageReceivedCallback callback, ImageZoomView view,
				String photoPathName) {
			this.mCallback = callback;
			this.mView = view;
			this.mPhotoPathName = photoPathName;
		}

		@Override
		public void run() {
			Bitmap bitMap = BitmapFactory.decodeFile(mPhotoPathName);
			ImageDisplayer displayer = new ImageDisplayer(mView, bitMap);
			mCallback.onImageReceived(displayer);

		}

	}

}
